package com.kotlin.android.ktx.ext

import android.content.Context
import android.view.View
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment

/**
 *
 * Created on 2020/4/21.
 *
 * @author o.s
 */

fun Context?.toast(content: String?, duration: Int = Toast.LENGTH_SHORT) {
    this?.apply {
        if (content.orEmpty().isBlank()) {
            return
        }
        Toast.makeText(this, content, duration)?.apply {
            show()
        }
    }
}

fun Context?.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    this?.apply {
        toast(getString(id))
    }
}

fun Fragment?.toast(content: String?, duration: Int = Toast.LENGTH_SHORT) {
    this?.context?.apply {
        toast(content)
    }
}

fun Fragment?.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    this?.context?.apply {
        toast(getString(id))
    }
}

fun View?.toast(content: String?, duration: Int = Toast.LENGTH_SHORT) {
    this?.context?.apply {
        toast(content)
    }
}

fun View?.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    this?.context?.apply {
        toast(getString(id))
    }
}

fun Any.toast(context: Context?, content: String?, duration: Int = Toast.LENGTH_SHORT) {
    context?.apply {
        toast(content)
    }
}

fun Any.toast(context: Context?, @StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    context?.apply {
        toast(getString(id))
    }
}
